package com.yima.baseproj.module.sys.bill;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yima.baseproj.aop.log.Logging;
import com.yima.baseproj.module.config.utils.PageUtil;
import com.yima.baseproj.module.config.utils.PageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(tags = "订单管理")
@RequestMapping("/api/sys/bill")
@RestController
public class BillController {

    @Autowired
    private BillService billService ;

    @Logging(tags = "订单管理",value = "查询分页")
    @PreAuthorize("hasAuthority('sys:bill:findAllByPage')")
    @ApiOperation("查询分页")
    @GetMapping("/findAllByPage")
    public Object findAllByPage(PageVo page, BillEntity searchModel) {
        Page<Map> pageData = billService.findAllByPage(PageUtil.initMpPage(page),searchModel);
        return pageData;
    }

    @Logging(tags = "订单管理",value = "添加")
    @PreAuthorize("hasAuthority('sys:bill:add')")
    @ApiOperation("添加")
    @PostMapping("/add")
    public void saveUser(@RequestBody @Validated BillEntity customAdmin) {

        billService.add(customAdmin);
    }


    @ApiOperation("根据id查询订单信息")
    @GetMapping("/findById/{id}")
    public BillEntity findById(@PathVariable int id){
        BillEntity billEntity = billService.findById(id);
        return billEntity;
    }


    @Logging(tags = "订单管理",value = "修改")
    @PreAuthorize("hasAuthority('sys:bill:edit')")
    @ApiOperation("修改")
    @PostMapping("/edit")
    public void editcl(@RequestBody @Validated BillEntity customAdmin) {
        billService.edit(customAdmin);
    }

    @Logging(tags = "订单管理",value = "删除")
    @PreAuthorize("hasAuthority('sys:bill:delByIds')")
    @ApiOperation("删除")
    @DeleteMapping(value = "/delByIds/{ids}")
    public void delByIds(@PathVariable int ids) {

        billService.delByIds(ids);
    }


}
